﻿using System.Collections.Generic;
using AutoMapper;

namespace OrderMicroService.Application.Assembler
{
    public abstract class DtoAssmbler
    {
        protected readonly Mapper mapper;

        public DtoAssmbler(Mapper mapper)
        {
            this.mapper = mapper;
        }

        public TDto ToDto<TEntity, TDto>(TEntity source)
        {
            return mapper.Map<TEntity, TDto>(source);
        }

        public IEnumerable<TDto> ToDtos<TEntity, TDto>(IEnumerable<TEntity> source)
        {
            return mapper.Map<IEnumerable<TEntity>, IEnumerable<TDto>>(source);
        }

        public TEntity ToEntity<TDto, TEntity>(TDto source)
        {
            return mapper.Map<TDto, TEntity>(source);
        }

        public IEnumerable<TEntity> ToEntitys<TDto, TEntity>(IEnumerable<TDto> source)
        {
            return mapper.Map<IEnumerable<TDto>, IEnumerable<TEntity>>(source);
        }
    }
}